package com.cqie.teacherserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cqie.campuscommon.result.Result;
import com.cqie.teacherserver.entity.TeacherBaseInfo;
import com.cqie.teacherserver.mapper.TeacherBaseInfoMapper;
import com.cqie.teacherserver.service.ITeacherBaseInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 教师基本信息 服务实现类
 * </p>
 *
 * @author zhangr132
 * @since 2024-05-31
 */
@Slf4j
@Service
public class TeacherBaseInfoServiceImpl extends ServiceImpl<TeacherBaseInfoMapper, TeacherBaseInfo> implements ITeacherBaseInfoService {

    /**
     * 教师基本信息获取
     * @param teacherCode
     * @return
     */
    @Override
    public Result getTeacherBaseInfo(String teacherCode) {
        log.info("正在处理教师基本信息获取请求");

        TeacherBaseInfo teacherBaseInfo = getBaseInfo(teacherCode);
        if (teacherBaseInfo != null) {
            log.info("教师基本信息："+teacherBaseInfo);
            return Result.Success(teacherBaseInfo);
        }
        log.info("教师基本信息获取失败");
        return Result.Failed("教师基本信息获取失败");
    }













    /**
     * 封装方法
     * 获取教师基本信息
     * @param teacherCode
     * @return
     */
    private TeacherBaseInfo getBaseInfo(String teacherCode) {
        QueryWrapper<TeacherBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(TeacherBaseInfo::getGh, teacherCode);
        TeacherBaseInfo teacherBaseInfo = this.getOne(queryWrapper);
        return teacherBaseInfo;
    }
}
